﻿namespace DotRas
{
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Globalization;

    internal static class ThrowHelper
    {
        private static string FormatResourceString(string resource, params object[] args)
        {
            return string.Format(CultureInfo.CurrentCulture, resource, args);
        }

        public static void ThrowArgumentException(string argumentName, string resource)
        {
            ThrowArgumentException(argumentName, resource, new object[0]);
        }

        public static void ThrowArgumentException(string argumentName, string resource, params object[] args)
        {
            List<object> list = new List<object>(args);
            list.Insert(0, argumentName);
            throw new ArgumentException(FormatResourceString(resource, list.ToArray()), argumentName);
        }

        public static void ThrowArgumentNullException(string argumentName)
        {
            throw new ArgumentNullException(argumentName);
        }

        public static void ThrowArgumentOutOfRangeException(string argumentName, object actualValue, string resource)
        {
            throw new ArgumentOutOfRangeException(argumentName, actualValue, FormatResourceString(resource, new object[] { argumentName }));
        }

        public static void ThrowInvalidHandleException(RasHandle handle, string resource)
        {
            throw new InvalidHandleException(handle, resource);
        }

        public static void ThrowInvalidHandleException(RasHandle handle, string argumentName, string resource)
        {
            throw new InvalidHandleException(handle, FormatResourceString(resource, new object[] { argumentName }));
        }

        public static void ThrowInvalidOperationException(string resource)
        {
            throw new InvalidOperationException(resource);
        }

        public static void ThrowNotSupportedException(string message)
        {
            throw new NotSupportedException(message);
        }

        public static void ThrowRasException(int errorCode)
        {
            throw new RasException(errorCode);
        }

        public static void ThrowUnauthorizedAccessException(string message)
        {
            throw new UnauthorizedAccessException(message);
        }

        public static void ThrowWin32Exception()
        {
            throw new Win32Exception();
        }
    }
}

